package edu.stanford.prpl.app.prpltalk;

import java.util.ArrayList;
import java.util.List;

public class Notification {

	private boolean responseSeen = false;
	private int sleepTimeout = 1000;
	private List<String> resourceURIs;

	public Notification() {
		this.resourceURIs = new ArrayList<String>();
	}

	public synchronized List<String> getResourceURIs() throws Throwable {

		while (!responseSeen) {
			wait(sleepTimeout);
		}

		List<String> oldList = this.resourceURIs;
		this.resourceURIs = new ArrayList<String>();
		this.responseSeen = false;
		return oldList;
	}

	public synchronized void addResourceURIs(String[] resourceURIs) {
		for (int i = 0; i < resourceURIs.length; i++) {
			this.resourceURIs.add(resourceURIs[i]);
		}
		responseSeen = true;
		notifyAll();
	}

}
